#include "ros/ros.h"
#include "myxfei/voiceSrv.h"
#include "myxfei/ttsSrv.h"
#include "myxfei/myxfeiSrv.h"
#include <cstdlib>

int main(int argc,char **argv)
{
    ros::init(argc,argv,"testClient");
    ros::NodeHandle n;

    ros::ServiceClient testClient1 = n.serviceClient<myxfei::voiceSrv>("voice_recognition_server");
    ros::ServiceClient testClient2 = n.serviceClient<myxfei::ttsSrv>("tts_service");
    ros::ServiceClient testClient3 = n.serviceClient<myxfei::myxfeiSrv>("myxfeisrv");

    myxfei::voiceSrv srv1;
    myxfei::ttsSrv srv2;
    myxfei::myxfeiSrv srv3;
    if(argc != 2)
    {
        ROS_INFO("input error\n");
        return 0;
    }
    int choice = atoi(argv[1]);
    switch (choice)
    {
    case 0:
        ROS_INFO("test voice_recognition_service-name");
        srv1.request.type = 0;

        if(testClient1.call(srv1))
        {
            ROS_INFO("testClient result: %s",srv1.response.result.c_str());
        }
        else
        {
            ROS_ERROR("VRS Failed to call");
            return 1;
        }
        break;
    case 1:
        ROS_INFO("test voice_recognition_service-thing");
        srv1.request.type = 1;

        if(testClient1.call(srv1))
        {
            ROS_INFO("testClient result: %s",srv1.response.result.c_str());
        }
        else
        {
            ROS_ERROR("VRS Failed to call");
            return 1;
        }
        break;
    case 2:
        ROS_INFO("test tts_service");
        if(atoi(argv[2]) == 1)
            srv2.request.voice = "Hello,what's your name?";
        else
            srv2.request.voice = "What can I help you?";
        

        if(testClient2.call(srv2))
        {
            ROS_INFO("succeed tts");
        }
        else
        {
            ROS_ERROR("TTS Failed to call");
            return 1;
        }
        break;
    case 3:
        ROS_INFO("test myxfeiservice 1");
        srv3.request.state = 1;
        if(testClient3.call(srv3))
        {
            ROS_INFO("name is %s,thing is %s.",srv3.response.name.c_str(),srv3.response.thing.c_str());
        }
        else
        {
            ROS_ERROR("myxfeiService1 error");
            return 0;
        }
        break;
    case 4:
        ROS_INFO("test myxfeiservice 2");
        srv3.request.state = 2;
        srv3.request.backname = "Jack";
        srv3.request.ishavething = true;
        if(testClient3.call(srv3))
        {
            ROS_INFO("myxfeiservice2 is finished");
        }
        else
        {
            ROS_ERROR("myxfeiService2 error");
            return 0;
        }
        break;

    default:
        break;
    }

    return 0;
}
